package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface SetmealMapper {
    @Select("select count(*) from setmeal where category_id=#{id}")
    int findSetMealWithCategory(long id);

    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(SetmealDto setmealDto);

    List<Setmeal> findByName(@Param("name") String name);


    int findSetmealWithStatus(@Param("ids") List<Long> ids);


    void deleteByIds(@Param("ids") List<Long> ids);

    @Select("select * from setmeal where category_id = #{categoryId} and status=#{status}")
    List<Setmeal> list(Long categoryId, Integer status);

    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);


    @Update("update setmeal set category_id=#{categoryId},name=#{name},price=#{price},description=#{description},image=#{image},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void updateSetmeal(SetmealDto setmealDto);

    void updateStatus(@Param("ids") List<Long> ids, @Param("setmeal")Setmeal setmeal, @Param("status")Integer status);
}
